function AFOSR(NAME);

%AFOSR load and test,....validate?
%Parse into meaning data

%clear all;


%NAME = 'S0003_1';
Dfile = strcat(NAME, '.xdf');

%make a folder to upload data to the cloud
if(exist('ToUpload','dir')~=7)
    mkdir('ToUpload')
end

%unpack the xdf file and synch the time streams correctly.
try 
  [streams,fileheader] = load_xdf(Dfile);
catch
  disp('Something screwed up with loading the xdf file.  Trying a different method')
  [streams,fileheader] = load_xdf(Dfile, 'Verbose', true, ...
      'HandleClockSynchronization', false, 'HandleJitterRemoval', false);
end                          

%grab a list of stream names,...the streams are not always in the same
%order from subject to subject
numStreams = size(streams,2);

%go through the xdf file and parse the data files into usable data
for i = numStreams:-1:1
  StreamNames{i,1} = streams{i}.info.name;
   if strcmp(streams{i}.info.name, 'AudioCaptureWin')
       if strcmp(streams{i}.info.hostname, 'daq3')
           Mic = streams{1,i};
           streams{1,i} = [];
           continue;
       elseif strcmp(streams{i}.info.hostname, 'daq1')
           AudioIn = streams{1,i};
           streams{1,i} = [];
           continue;
       end
   end
   if strcmp(streams{i}.info.name, 'DOIT_AFOSR1')
       Physio =  streams{1,i};
       streams{1,i} = [];
       continue;
   end
   if strcmp(streams{i}.info.name, 'NeuroEEG')
       if strcmp(streams{i}.info.type, 'Accelerometer')
           EEG_accel =  streams{1,i};
           streams{1,i} = [];
           continue;
       end  
   end
   if strcmp(streams{i}.info.name, 'NeuroEEG')
       if strcmp(streams{i}.info.type, 'Markers')
           streams{1,i} = [];
           continue;
       end
   end
   if strcmp(streams{i}.info.name, 'NeuroEEG')
       if strcmp(streams{i}.info.type, 'Quality')
           EEG_qual =  streams{1,i};
           streams{1,i} = [];
           continue;
       end
   end
   if strcmp(streams{i}.info.name, 'NeuroEEG')
       if strcmp(streams{i}.info.type, 'EEG')
           EEG =  streams{1,i};
           streams{1,i} = [];
       end
      continue;
   end
   if strcmp(streams{i}.info.name, 'pupil_capture')
       if strcmp(streams{i}.info.type, 'Gaze')
           pupil_gaze =  streams{1,i};
           streams{1,i} = [];
       end
       continue;
   end
   if strcmp(streams{i}.info.name, 'NIRStarTriggers')
       if strcmp(streams{i}.info.type, 'Triggers')
           streams{1,i} = [];
       end
       continue;
   end 
   if strcmp(streams{i}.info.name, 'NIRStar')
       if strcmp(streams{i}.info.type, 'NIRS')
           NIRS =  streams{1,i};
           streams{1,i} = [];
       end
       continue;
   end
   if strcmp(streams{i}.info.name, 'SimCreator')
       SIM =  streams{1,i};
       streams{1,i} = [];
       continue;
   end
   if strcmp(streams{i}.info.name, 'Cam')
       if strcmp(streams{i}.info.hostname, 'daq3')
           Cam_front =  streams{1,i};
           streams{1,i} = [];
           continue;
       end     
   end
   if strcmp(streams{i}.info.name, 'Cam')
       if strcmp(streams{i}.info.hostname, 'daq1')
           Cam_side =  streams{1,i};
           streams{1,i} = [];
           continue;
       end
   end
end

%create audio file that has 1 channel of the lappel mic (subject's response)
%and one channel that is audio in (simulation audio and dialogue questions).
% It does not return any new info, just writes out an audio file in the
% folder
% It also amplifies the audio input to the max amount possible
makeAudioFile(AudioIn, Mic, NAME);

%calbrates the physio data into correct units and useful data
Physio = calPhysio(Physio, NAME);

%writes out the channel names of the time series
pupil_gaze = parseGaze(pupil_gaze, NAME);

%make a data file of just the raw fnir data
NIRS = parseNIRS(NIRS, NAME);


save(NAME);


